package com.tencent.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tencent.pojo.*;
import com.tencent.service.CourseService;
import com.tencent.common.pojo.Result;
import com.tencent.common.pojo.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.List;

/**
 * @author : wangbo
 * @version : 1.0
 * @date :Create in 2021/4/18
 * @description :
 */



@RestController
@RequestMapping("/course")
@CrossOrigin
public class CourseController {

    @Autowired
    CourseService courseService;
    /**
     * 课程列表接口查询
     * @param course
     * @return
     */
    @RequestMapping("/courseList")
    public IPage getList(@RequestBody Course course){
       IPage page= courseService.getList(course);
       return  page;
    }
/**
 * getByCourseID
  */
  @RequestMapping("/getByID")
    public Result getByID(@RequestParam("id") BigInteger id){
        Course course=courseService.getById(id);
      return  new Result(StatusCode.OK,"查询成功",true,course);
  }

  @RequestMapping("/getPater")
    public Result getPaterById(@RequestParam("id") BigInteger id){
     List<Chapter> list= courseService.getPaterById(id);
      return new Result(StatusCode.OK,"查询成功",true,list);
  }


//    /**
//     * s上传视频
//     */
//    SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy/MM/dd");
//
//
//    @RequestMapping("/add")
//    public Result add(@RequestPart("multipartFile") MultipartFile multipartFile, HttpServletRequest request) {
//        Map<String,Object> map=new HashMap<>();
//        String originalFilename = multipartFile.getOriginalFilename();
//        if(!originalFilename.endsWith(".mp4")){
//            return new Result(StatusCode.ERROR,"文件类型不对",false);
//        }
//        String format = simpleDateFormat.format(new Date());
//        System.out.println("format是:" + format);
//        String newName = UUID.randomUUID().toString() + ".mp4";
//        String objectName=format+newName;
//        Result result = OSSUtils.createOSSClient(objectName, multipartFile);
//       System.err.println(result.getData().toString());
//        return result;
//    }

    /**
     * //添加数据
     * @return
     */
    @RequestMapping("/addVideos")
    public Result save(@RequestBody Videos videos){
        courseService.save(videos);
        return new Result(StatusCode.OK,"添加视频成功",true);
    }

    /**
     * 删除课程
     * @return
     */
    @RequestMapping("/deleteCourse")
    public Result deleteCourseById(@RequestParam("id") BigInteger id ){
     courseService.deleteCourseById(id);
     return new Result(StatusCode.OK,"删除课程成功",true);
    }


    /**
     * 修改课程
     * @param course
     * @return
     */
    @RequestMapping("/updateCourse")
    public Result updateCourse(@RequestBody Course course){
        courseService.updateCourse(course);
        return new Result(StatusCode.OK,"修改课程成功",true);
    }

    /**
     * 全部方向
     * @return
     */
    @RequestMapping("/getTager")
    public Result getTager(){
       List<Tager> list= courseService.getAlltager();
        return new Result(StatusCode.OK,"修改课程成功",true,list);
    }


    /**
     * 全部类型
     * @return
     */
    @RequestMapping("/getCourseType")
    public Result  getCourseType(){
        List<CourseType> list= courseService. getCourseType();
        return new Result(StatusCode.OK,"修改课程成功",true,list);
    }

    /**
     * 全部类型
     * @return
     */
    @RequestMapping("/getTypeId")
    public Result  getCourseTypeId(@RequestParam("tagerId") int tagerId){
        List<CourseType> list= courseService. getCourseTypeId(tagerId);
        return new Result(StatusCode.OK,"修改课程成功",true,list);
    }


}
